package com.chang.rentmall.controllers;

import com.chang.rentmall.forms.AddGoodsFormBean;
import com.chang.rentmall.servicesImpl.GoodsServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;

@RestController
public class GoodsController {
    @Autowired
    GoodsServiceImpl goodsServiceImpl;

    /**
     * 新建商品
     * @param AddGoodsFormBean
     * @return
     */
    @RequestMapping(value = "/goods/create", method = {RequestMethod.POST})
    public HashMap<String, Object> addGoods (@RequestBody @Valid AddGoodsFormBean addGoodsFormBean) {
    	return goodsServiceImpl.addGoods(addGoodsFormBean.getForm());
    }
    
    /**
     * 查询商铺商品
     * @param AddGoodsFormBean
     * @return
     */
    @RequestMapping(value = "/goods/list", method = {RequestMethod.POST})
    public HashMap<String, Object> getGoodsByShop (@RequestBody AddGoodsFormBean addGoodsFormBean) {
        return goodsServiceImpl.getGoodsByShop(addGoodsFormBean);
    }
    
    /**
     	* 修改商品
     * @param AddGoodsFormBean
     * @return
     */
    @RequestMapping(value = "/goods/update", method = {RequestMethod.POST})
    public HashMap<String, Object> updateGoods (@RequestBody AddGoodsFormBean addGoodsFormBean) {
        return goodsServiceImpl.updateGoods(addGoodsFormBean.getForm());
    }
    
    /**
     * 根据id获取商品详情
     * @param addressFormBean
     * @return
     */
    @RequestMapping(value = "/goods/detail", method = {RequestMethod.POST})
    public HashMap<String, Object> getGoodsById (@RequestBody AddGoodsFormBean addGoodsFormBean) {
        return goodsServiceImpl.getGoodsById(addGoodsFormBean.getQuery().getId());
    }
    
    /**
 	* 修改商品状态
	 * @param AddGoodsFormBean
	 * @return 
	 */
    @RequestMapping(value = "/goods/updateStatus", method = {RequestMethod.POST})
    public HashMap<String, Object> updateGoodsStatus (@RequestBody AddGoodsFormBean addGoodsFormBean) {
    return goodsServiceImpl.updateGoodsStatus(addGoodsFormBean);
}
    
}
